package com.gears_software.sxdc.dccx.ui.view;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.gears_software.sxdc.dccx.R;
import com.gears_software.sxdc.dccx.data.finder.RequestUrl;
import com.gears_software.sxdc.dccx.data.model.VouchersModel;
import com.j256.ormlite.stmt.query.In;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import java.text.SimpleDateFormat;

/**
 * Created by chezhenzhen on 2017/11/22.
 */

@EViewGroup(R.layout.item_view_nouse_vouchers)
public class VouchersItemView extends LinearLayout {
    @ViewById
    TextView txt_price;
    @ViewById
    TextView txt_type;
    @ViewById
    TextView txt_date;
    @ViewById
    TextView txt_startwire;
    @ViewById
    RelativeLayout re_bg;
    @ViewById
    SimpleDraweeView vouchers_img;
    Context context;

    public VouchersItemView(Context context) {
        super(context);
        this.context = context;
    }

    public void bind(VouchersModel vouchersModel) {
        if (vouchersModel != null) {
            if (vouchersModel.getVouchertypeid().equals("1")) {
                txt_type.setText("现金类");
                txt_price.setText(vouchersModel.getDiscountamount().toString() + "元");
            } else if (vouchersModel.getVouchertypeid().equals("2")) {
                txt_type.setText("折扣类");
                float rate = Float.valueOf(Float.valueOf(vouchersModel.getDiscountrate().toString()) * 10);
                txt_price.setText((rate + "折").replace(".0",""));
            }
            txt_startwire.setText("(满"+vouchersModel.getStartwire().toString().replace(".00","")+"元可用)");
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            String endStr = sf.format(vouchersModel.getEnddate());
            txt_date.setText("有效期至" + endStr);
            if (vouchersModel.getStatusid().equals("1")) {
                re_bg.setBackgroundResource(R.drawable.circle_orange);
            } else if (vouchersModel.getStatusid().equals("2")) {
                re_bg.setBackgroundResource(R.drawable.circle_gray);
            }
            if (vouchersModel.getVoucherspicturesurl() != null && !vouchersModel.getVoucherspicturesurl().equals("")) {
                Uri uri = Uri.parse(vouchersModel.getVoucherspicturesurl() + RequestUrl.card);
                vouchers_img.setImageURI(uri);
            }
        }
    }
}
